package com.caipos.actor.ruleChain;

import com.caipos.actor.common.data.id.RuleChainId;
import com.caipos.actor.common.msg.KbActorStopReason;
import com.caipos.actor.common.msg.KbMsg;
import com.caipos.actor.common.msg.KbRuleEngineActorMsg;
import com.caipos.actor.common.msg.RuleChainAwareMsg;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

@EqualsAndHashCode(callSuper = true)
@ToString
public abstract class KbToRuleChainActorMsg extends KbRuleEngineActorMsg implements RuleChainAwareMsg {

    @Getter
    private final RuleChainId target;

    public KbToRuleChainActorMsg(KbMsg msg, RuleChainId target) {
        super(msg);
        this.target = target;
    }

    @Override
    public RuleChainId getRuleChainId() {
        return target;
    }

    @Override
    public void onKbActorStopped(KbActorStopReason reason) {
        String message = reason == KbActorStopReason.STOPPED ? String.format("Rule chain [%s] stopped", target.getId()) : String.format("Failed to initialize rule chain [%s]!", target.getId());
    }
}
